<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/13
 * Time: 16:02
 */

function send_commission($mid,$uid,$moneynum,$level,$achievement){
    $lock = M('register')->where(array('id'=>$uid))->getField('lock');
    $update_time = M('register')->where(array('id'=>$uid))->getField('update_time');
    $tel = M('register')->where(array('id'=>$uid))->getField('tel');
    $commission = $moneynum;
    if ($lock)
    {
        // 增加会员的佣金
        $s1=M('register')->where(['id'=>(int)$uid])->setInc('commissions', (float)$commission);

        //如果结算日期为当天日期，则更新昨日佣金
        $date = strtotime(I('date')) > 0 ? date('Y-m-d', strtotime(I('date'))) : date('Y-m-d');

        if($date!=date('Y-m-d',strtotime($update_time)))
        {
            //echo 113;
            M('register')
                ->where(['id'=>$uid])
                ->save(array(
                    "commission"=>0
                ));

        }
        $datetime['update_time'] = date('Y-m-d H:i:s');

        M('register')->where(['id'=>$uid])->setInc('commission', $commission);

        M('register')->where(['id'=>$uid])->save($datetime);

        // 添加工资奖金记录
        $s2=M('bonus')->add([
            'mid' => $mid,
            'tel' => $tel,
            'time' => $achievement['createtime'],
            'TCJE' => $achievement['tcje'],
            'jsmc' => $achievement['jsmc'],
            'stime' => $date . date(' H:i:s'),
            'uid' => $uid,
            'money' => $commission,
            'remark' => $level
        ]);
    }
    if($s1&&$s2){
        return 1234;
    }
}